﻿@model PagedList.IPagedList<CP_SchoolForChildren_v0._1.Models.RelatedModel.ArticleModel>
@using CP_SchoolForChildren_v0._1.Controllers.Support
@using CP_SchoolForChildren_v0._1.Models.DataModel;


@{
    ViewBag.Title = "Chăm sóc bé yêu";
    Layout = "~/Views/Shared/FE/_Layout_FE_Index.cshtml";
    SFCEntities db = new SFCEntities();
}
<link href="@Url.Content("~/Content/FE/Addition.css")" rel="stylesheet" type="text/css" />
<div class="allhome" style="padding-top: 15px;">
    <div class="dashboard" style="width: 305px;">
        <div class="content-header">
            <div class="header-inner">
                <h2><a href="@Url.Action("Index")">Chuyên mục</a></h2>
                <br class="spacer"/>
                <ol class="rectangle-list">
                    @{
                        List<Category> category = (from c in db.Categories
                                                   select c).ToList<Category>();

                        for (int i = 1; i <= category.Count; i++)
                        {
                            <li> @Html.ActionLink(category[i - 1].CategoryName, "ViewArticleByCategory", new { id = category[i - 1].CategoryID })</li>
                        }

                    }
                </ol>
            </div>
        </div>
    </div>
    <div class="content-main" style="width: 650px;">
        <style type="text/css">
            .box-content b,strong {
                font-weight: normal;
            }
        </style>
        @foreach (var item in Model)
        {
            <div class="boxMod">
                <div id="box-content-136" class="boxmd-cont4">
                    <div class="newest-cont clearfix">
                        <a href="@Url.Action("Details", new { id = item.ArticleID })">
                            @{
                                var fc = new FunctionController();
                                string iurl = fc.FirstImage(@item.ArticleContent);
                                if (iurl == null || iurl == "")
                                {
                                    iurl = Url.Content("~/AvartarUser/default_artice.jpg");
                                }
                            }
                            <img src="@iurl" height="100" width="150px" class="img-listcat">
                        </a>
                        <div style="float: right; padding-left: 15px; width: 400px">
                            <p style="margin-bottom: 10px;">@Html.ActionLink(@item.Title, "Details", new { id = item.ArticleID })</p>                    
                            <div class="box-content">
                                @{
                                    var content = fc.StripHTML(item.ArticleContent);
                                    if(content.Length > 200)
                                    {
                                        var tmp = content;
                                        content = tmp.Substring(0, 200);
                                        var idx = content.LastIndexOf(' ');
                                        if(idx > -1)
                                        {
                                            content = content.Remove(idx);
                                        }
                                    }
                                }
                                @Html.Raw(content) ...
                            </div>
                        </div>
                        
                    </div>
                    @if (User.Identity.Name != "")
                    {
                        string name = User.Identity.Name;
                        var user = (from u in db.Users
                                    where (u.UserName == name)
                                    select u).First();
                        var roleadmin = db.UserRoles.Single(ur => ur.RoleName == "Admin");
                        int userid = user.UserID;
                        if (userid == item.UserID ||
                            user.RoleID == roleadmin.RoleID)
                        {
                            <p id="article-cp"> @Html.ActionLink("Chỉnh sửa", "Edit", new { id = item.ArticleID }) 
                                | @Html.ActionLink("Xóa", "Delete", new { id = item.ArticleID }, new { onclick = "return confirm('Bạn có chắc chắn muốn xóa?');" })</p>
                                
                        }
                    }
                </div>
                
            </div>
        }
        @if (Model.PageCount > 1)
        {
            <div style="padding: 10px;">
                <div class="paging" style="float: right;">
                    Trang <span style="font-weight: bold">@(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)</span>
                    / <span style="font-weight: bold">@Model.PageCount</span>
     
                    @if (Model.HasPreviousPage)
                    {
                        @Html.ActionLink("Trang đầu", "Index", new {page = 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter})
                        @Html.Raw(" ")
                        ;
                        @Html.ActionLink("<", "Index", new {page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter})
                    }
     
                    @if (Model.HasNextPage)
                    {
                        @Html.ActionLink(">", "Index", new {page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter})
                        @Html.Raw(" ")
                        ;
                        @Html.ActionLink("Trang cuối", "Index", new {page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter})
                    }
                </div>
                <br class="spacer"/>
            </div>
        }
        <br class="spacer"/>
    </div>
    <br class="spacer"/>
</div>